import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:ytbusiness/page/message_notice/chat_room/chat_item.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';
import 'package:ytbusiness/widgets/widgets.dart';

//聊天室
class ChatRoom extends StatefulWidget {
  final Map<String, dynamic> arguments;

  const ChatRoom({Key key, this.arguments}) : super(key: key);

  @override
  _ChatRoomState createState() => _ChatRoomState();
}

class _ChatRoomState extends State<ChatRoom> {
  bool showChatMenu = true;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: () {
        //输入框失焦
        FocusScope.of(context).requestFocus(FocusNode());
        //关闭聊天功能菜单
        setState(() {
          showChatMenu = true;
        });
      },
      child: Scaffold(
        backgroundColor: Color(0xffE5E5E5),
        appBar:
            customAppBar(context, title: widget.arguments["title"] as String),
        body: Stack(
          children: [
            Container(),
            Container(
              margin: EdgeInsets.only(bottom: setWidth(49)),
              child: ListView.builder(
                  itemCount: 20,
                  itemBuilder: (context, index) {
                    return ChatItem(type: index);
                  }),
            ),
            Positioned(
              bottom: 0,
              left: 0,
              right: 0,
              child: Column(
                mainAxisAlignment: MainAxisAlignment.end,
                crossAxisAlignment: CrossAxisAlignment.end,
                children: [
                  Container(
                    width: setWidth(375),
                    decoration: BoxDecoration(
                      color: Color(0xffF1F1F1),
                      border: Border(
                        top: BorderSide(
                          width: setWidth(0.5),
                          color: Color(0xffD3D7DA),
                        ),
                      ),
                    ),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.end,
                      crossAxisAlignment: CrossAxisAlignment.end,
                      children: [
                        InkWell(
                          onTap: () {
                            print('语音点击时间!!!  ');
                          },
                          child: Container(
                            margin: EdgeInsets.only(
                                bottom: setWidth(8.5),
                                left: setWidth(10.5),
                                right: setWidth(10.5)),
                            child: Image.asset(
                              'assets/images/voice_image.png',
                              width: setWidth(31),
                              height: setWidth(31),
                              fit: BoxFit.cover,
                            ),
                          ),
                        ),
                        Expanded(
                          child: Container(
                            constraints: BoxConstraints(
                              maxHeight: 200.0,
                              minHeight: 36.0,
                            ),
                            decoration: BoxDecoration(
                                color: Colors.white,
                                borderRadius: BorderRadius.circular(18)),
                            margin: EdgeInsets.only(
                                top: setWidth(7), bottom: setWidth(7)),
                            child: TextField(
                              style: TextStyle(fontSize: setSp(16)),
                              maxLines: null,
                              onTap: () {
                                //关闭聊天功能菜单
                                setState(() {
                                  showChatMenu = true;
                                });
                              },
                              decoration: InputDecoration(
                                contentPadding: EdgeInsets.only(
                                    left: setWidth(15),
                                    top: setWidth(10),
                                    bottom: setWidth(10)),
                                isDense: true,
                                border: InputBorder.none,
                                focusedBorder: InputBorder.none,
                                enabledBorder: InputBorder.none,
                              ),
                            ),
                          ),
                        ),
                        Row(
                          children: [
                            Container(
                              margin: EdgeInsets.only(
                                  bottom: setWidth(9),
                                  left: setWidth(10),
                                  right: setWidth(10.5)),
                              child: Image.asset(
                                'assets/images/emoji.png',
                                width: setWidth(31),
                                height: setWidth(31),
                                fit: BoxFit.cover,
                              ),
                            ),
                            GestureDetector(
                              //打开、关闭聊天功能菜单
                              onTap: () {
                                setState(() {
                                  showChatMenu = !showChatMenu;
                                });
                              },
                              child: Container(
                                margin: EdgeInsets.only(bottom: setWidth(9)),
                                child: Image.asset(
                                  'assets/images/chat_add.png',
                                  width: setWidth(31),
                                  height: setWidth(31),
                                  fit: BoxFit.fill,
                                ),
                              ),
                            ),
                            SizedBox(
                              width: setWidth(12),
                            ),
                          ],
                        ),
                      ],
                    ),
                  ),
                  Offstage(
                    offstage: showChatMenu,
                    child: Container(
                      color: Color(0xffEDF1F2),
                      padding: EdgeInsets.only(
                          top: setWidth(22),
                          bottom: setWidth(45),
                          left: setWidth(26),
                          right: setWidth(26)),
                      child: Row(
                        children: [
                          Wrap(
                            spacing: setWidth(27),
                            children: [
                              Column(
                                children: [
                                  Container(
                                    width: setWidth(62),
                                    height: setWidth(62),
                                    child: Image.asset(
                                      'assets/images/select_image.png',
                                      width: setWidth(62),
                                      height: setWidth(62),
                                      fit: BoxFit.cover,
                                    ),
                                  ),
                                  SizedBox(
                                    height: setWidth(8),
                                  ),
                                  Container(
                                    child: Text(
                                      "相册",
                                      style: TextStyle(
                                          color: Color(0xff747B81),
                                          fontSize: setSp(12)),
                                    ),
                                  )
                                ],
                              ),
                              Column(
                                children: [
                                  Container(
                                    width: setWidth(62),
                                    height: setWidth(62),
                                    child: Image.asset(
                                      'assets/images/select_location.png',
                                      width: setWidth(62),
                                      height: setWidth(62),
                                      fit: BoxFit.cover,
                                    ),
                                  ),
                                  SizedBox(
                                    height: setWidth(8),
                                  ),
                                  Container(
                                    child: Text(
                                      "位置",
                                      style: TextStyle(
                                          color: Color(0xff747B81),
                                          fontSize: setSp(12)),
                                    ),
                                  )
                                ],
                              )
                            ],
                          ),
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
